package org.example;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;

/**
 * 测试每日订单生成（500万放款总额）
 */
public class TestDailyOrderGeneration {
    
    public static void main(String[] args) {
        System.out.println("=== 每日订单生成测试（500万放款总额） ===");
        
        // 配置参数
        LocalDate startDate = LocalDate.of(2023, 7, 1);
        LocalDate currentDate = LocalDate.now();
        int baseOrders = 300;
        int monthlyIncrease = 30;
        
        // 贷款金额配置
        int minLoanAmount = 3000; // 3000元
        int maxLoanAmount = 7000; // 7000元
        int avgLoanAmount = (minLoanAmount + maxLoanAmount) / 2; // 5000元
        
        System.out.println("贷款金额配置:");
        System.out.println("- 最小金额: " + minLoanAmount + " 元");
        System.out.println("- 最大金额: " + maxLoanAmount + " 元");
        System.out.println("- 平均金额: " + avgLoanAmount + " 元");
        
        System.out.println("\n订单数量配置:");
        System.out.println("- 基础订单数: " + baseOrders + " 个/月");
        System.out.println("- 每月递增: " + monthlyIncrease + " 个");
        System.out.println("- 订单创建时间: 每天随机分布");
        
        // 计算总订单数
        LocalDate month = startDate;
        int totalOrders = 0;
        int monthCount = 0;
        
        System.out.println("\n=== 每月订单数计算 ===");
        while (!month.isAfter(currentDate)) {
            int monthsFromStart = (int) (month.toEpochDay() - startDate.toEpochDay()) / 30;
            int monthlyOrders = baseOrders + (monthsFromStart * monthlyIncrease);
            totalOrders += monthlyOrders;
            monthCount++;
            
            // 计算每天平均订单数
            int daysInMonth = month.lengthOfMonth();
            double avgDailyOrders = (double) monthlyOrders / daysInMonth;
            
            System.out.println("月份: " + month + ", 订单数: " + monthlyOrders + 
                             ", 天数: " + daysInMonth + ", 平均每天: " + String.format("%.1f", avgDailyOrders) + " 个");
            
            month = month.plusMonths(1);
        }
        
        // 计算总放款金额
        BigDecimal totalLoanAmount = BigDecimal.valueOf(totalOrders).multiply(BigDecimal.valueOf(avgLoanAmount));
        
        System.out.println("\n=== 计算结果 ===");
        System.out.println("总月数: " + monthCount);
        System.out.println("总订单数: " + totalOrders);
        System.out.println("平均贷款金额: " + avgLoanAmount + " 元");
        System.out.println("总放款金额: " + totalLoanAmount.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) + " 万");
        
        // 验证是否达到目标
        BigDecimal targetLoanAmount = new BigDecimal("5000000"); // 500万
        
        System.out.println("\n=== 目标验证 ===");
        System.out.println("目标放款金额: 500万");
        System.out.println("实际放款金额: " + totalLoanAmount.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) + " 万");
        
        if (totalLoanAmount.compareTo(targetLoanAmount) >= 0) {
            System.out.println("✅ 放款金额达到目标");
        } else {
            System.out.println("❌ 放款金额未达到目标");
            BigDecimal shortage = targetLoanAmount.subtract(totalLoanAmount);
            System.out.println("缺口: " + shortage.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) + " 万");
        }
        
        // 显示订单时间分布特点
        System.out.println("\n=== 订单时间分布特点 ===");
        System.out.println("- 订单创建时间: 每天随机分布，不再集中在月初");
        System.out.println("- 客户创建时间: 与订单创建时间一致");
        System.out.println("- 放款时间(fr_time): 与客户创建时间一致");
        System.out.println("- 还款计划: 基于随机创建时间计算");
        
        // 显示Vintage波状图模式
        System.out.println("\n=== Vintage波状图模式 ===");
        System.out.println("第一期逾期率: 0.1%");
        System.out.println("第二期逾期率: 4.6%");
        System.out.println("第十期逾期率: 7.36%（峰值）");
        System.out.println("第二十四期逾期率: 4.56%");
    }
}




